use actix_web::{App, HttpServer, web};

use try_rust_web::handlers::{hello_controller, struct_controller};

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    println!("starting server ");

    HttpServer::new(|| App::new().configure(config))
        .bind("127.0.0.1:8080")?
        .run()
        .await
}

pub fn config(cfg: &mut web::ServiceConfig) {
    cfg.service(
        web::scope("/api")
            .service(
                web::scope("/structs")
                    .service(struct_controller::try_struct_handler)
                    .service(struct_controller::try_struct_rectangle)
                    .service(struct_controller::try_option),
            )
            .service(web::scope("/hello").service(hello_controller::hello)),
    );

    cfg.service(
        web::scope("/hello")
            .service(hello_controller::hello)
            .service(hello_controller::try_enum),
    );
}
